package lar.game.gamestate;

import javax.microedition.khronos.opengles.GL11;

import lar.system.engine.MainProgram;
import lar.system.engine.UI;
import lar.system.opengl.GLEmptyQuad;
import lar.system.sound.Sound;
import lar.system.R;

public class SlideTransition implements GameState 
{
	GameState prev,next;
	float progress;
	float direction;
	public SlideTransition(GameState prev, GameState next, boolean leftToRight)
	{
		this.prev = prev;
		this.next = next;
		progress = 0;
		direction = leftToRight ? 1 : -1;
	
	}
	
	public void gameFrame() 
	{
		UI.needRendering = true;
		float asp = MainProgram.glSurfaceView.getAspectRatio();
		progress+=0.15f*direction;
		if(progress > asp*2 || progress < -asp*2) MainProgram.gameLoop.ChangeState(next);
	}

	public void Draw(GL11 gl) 
	{
		float asp = MainProgram.glSurfaceView.getAspectRatio();
		gl.glPushMatrix(); 
		gl.glTranslatef(-progress, 0f, 0f);
		prev.Draw(gl);
		gl.glPopMatrix();
		gl.glPushMatrix();
		gl.glTranslatef(direction*2*asp-progress, 0f, 0f);
		next.Draw(gl);
		gl.glPopMatrix();
	}

	public void onPause() 
	{	
	
	}

	public void onResume() 
	{
		
	}

	public boolean CheckBounds(float x, float y) 
	{
		return false;
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onBack() {
		// TODO Auto-generated method stub
		
	}


}
